#
# 作业：
#     1、改造登录注册的程序
#         1、账号和密码存到文件里面
#         2、要判断用户是否存在
#


f = open('user.txt',encoding='UTF-8')
result =f.read()
slipt = result.split('\n')
L1 = []
for i in slipt:
    L = i.split(',')
    for k in L:
        L1.append(k)
L2 = L1[::2]
L3 = L1[1::2]
d=dict(zip(L2,L3))
for i in range(3):
    username = input('username：').strip()
    psd = input('请输入密码：').strip()
    cpsd = input('请再次输密码：').strip()
    if username == '' or psd == '' or cpsd == '':
        print('账号密码不能为空')
    elif username in d:
        print('用户名已经存在')
    elif psd != cpsd:
         print('两次密码输入不一致')
    else:
         print('注册成功')
         d.setdefault(username, psd)
         print(d)
    for key, value in d.items():
        result = key + ',' + value + '\n'
        f = open('user.txt', 'a', encoding='UTF-8')
        f.write(result)
        f.close()

